package com.smart.buss.ctrl;

import com.smart.primary.util.MoneyUtil;

import java.math.BigDecimal;
import java.util.*;

public class text {
    public static double zuixiao = 0.1;
    public static double beilu = 5;
    public static double bili = 0.8;

    public static void main(String[] args) {


        /**
         *  获取100 位的 打卡金
         */
        Map m=new HashMap();
        for(int i=0;i<1000;i++){
            m.put(i,(int)(1+Math.random()*10));
        }
        System.out.println(m);

        /**
         *  获取打卡金总和
         */
        int a=0;
        for (Object key : m.keySet()) {
            a+=(int)m.get(key);
        }
        System.out.println("打卡金总和"+a);

        /**
         * 获取奖池的金额
         */
        BigDecimal jiangchi= MoneyUtil.subToBig(MoneyUtil.mulToBig(a,bili),MoneyUtil.mulToBig(zuixiao,m.size()));
        System.out.println("奖池金额"+MoneyUtil.mulToBig(a,bili));
        System.out.println("奖池金额扣除保障金后"+jiangchi);


        /**
         * 分配奖金
         */
        for (Object key : m.keySet()) {

            BigDecimal zhidazhi=MoneyUtil.mulToBig(m.get(key),beilu);

            double val=Math.random()*zhidazhi.doubleValue();

          if(MoneyUtil.comp(jiangchi,val)){
              m.put(key,MoneyUtil.fmt(zuixiao+val));
              jiangchi=MoneyUtil.subToBig(jiangchi,val); //奖池金额逐步减少
          }else if(jiangchi.doubleValue()>0){
              m.put(key,MoneyUtil.addToBig(zuixiao,jiangchi));
              jiangchi=MoneyUtil.subToBig(jiangchi,jiangchi); //奖池金额扣完
          }else {
              m.put(key,MoneyUtil.fmt(zuixiao));
          }

        }
        System.out.println(m);


        /**
         *  获取已分配金总和
         */
        BigDecimal value=BigDecimal.ZERO;
        for (Object key : m.keySet()) {
            value=value.add(MoneyUtil.getVal(m.get(key)));
        }
        System.out.println("已派发金额"+MoneyUtil.fmt(value));

    }
}
